package com.sinothk.fc.goodsStockRecord.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sinothk.fc.goodsStockRecord.entity.GoodsStockRecordEntity;
import com.sinothk.fc.goodsStockRecord.entity.GoodsStockRecordSearchReq;
import com.sinothk.fc.goodsStockRecord.mapper.GoodsStockRecordMapper;
import com.sinothk.fc.goodsStockRecord.service.IGoodsStockRecordService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description: 进货单
 * @Author: Liangyt
 * @Date: 2022-09-21
 * @Version: V1.0
 */
@Service
public class GoodsStockRecordServiceImpl extends ServiceImpl<GoodsStockRecordMapper, GoodsStockRecordEntity> implements IGoodsStockRecordService {

    @Resource
    private GoodsStockRecordMapper goodsStockRecordMapper;

    @Override
    public IPage<GoodsStockRecordEntity> listForStore(Page<GoodsStockRecordEntity> page, GoodsStockRecordSearchReq searchReq) throws Exception {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (loginUser == null || StringUtils.isBlank(loginUser.getStoreId())) throw new Exception("当前用户没有门店id");
        searchReq.setStoreId(loginUser.getStoreId());

        return goodsStockRecordMapper.listForStore(page, searchReq);
    }
}
